package pchi.pchicamera.adapters;

import java.util.ArrayList;

import pchi.pchicamera.R;
import pchi.pchicamera.data.TouchImageView;
import pchi.pchicamera.helpers.BitmapHelpers;
import pchi.pchicamera.helpers.LayoutHelpers;

import android.app.Activity;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;

public class FullScreenImageAdapter extends PagerAdapter {

	private Activity activity;
	private ArrayList<String> imagesPath;
	private LayoutInflater inflater;

	public FullScreenImageAdapter(Activity activity,
			ArrayList<String> imagePaths) {
		this.activity = activity;
		this.imagesPath = imagePaths;
		this.inflater = LayoutInflater.from(this.activity);
	}

	@Override
	public Object instantiateItem(ViewGroup container, int position) {
		TouchImageView imgDisplay;

		View viewLayout = this.inflater.inflate(R.layout.fullscreen_image,
				container, false);

		imgDisplay = (TouchImageView) viewLayout.findViewById(R.id.touchImg);

		BitmapHelpers.loadBitmap(imagesPath.get(position), imgDisplay,
				LayoutHelpers.getDeviceWidth(activity), 0);

		((ViewPager) container).addView(viewLayout);

		return viewLayout;
	}

	@Override
	public int getCount() {
		return this.imagesPath.size();
	}

	@Override
	public boolean isViewFromObject(View view, Object object) {
		return view == ((RelativeLayout) object);
	}

	@Override
	public void destroyItem(ViewGroup container, int position, Object object) {
		((ViewPager) container).removeView((RelativeLayout) object);
	}

}
